<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        /* 水平垂直居中   先移动50%到中  
        再反方向控制移动自身一半*/
        .bo{
            width: 200px;
            height: 200px;
            background :yellow;
            position: absolute;
            top: 50%;
            left: 50%;
            /* 利用外边距 反方向移动*/
            margin-left:-100px;
            margin-top: -100px;
        }
        .fa{
            width: 500px;
            height: 500px;
            background-color:yellow;
            margin: 0 auto;
            position: relative;
        }
        .ch{
            width: 200px;
            height: 200px;
            background-color:red;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -100px;
            margin-left: -100px;
        }
    </style>
</head>
<body>
    <!-- <div class="bo"></div> -->
    <div class="fa">
        <div class="ch"></div>
    </div>
</body>
</html>